var path = require('path');
var webpack = require('webpack');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
//定义了一些文件夹的路径
var ROOT_PATH = path.resolve(__dirname);
var APP_PATH = path.resolve(ROOT_PATH, 'app');
var BUILD_PATH = path.resolve(ROOT_PATH, 'build');

module.exports = {
  //项目的文件夹 可以直接用文件夹名称 默认会找index.js 也可以确定是哪个文件名字
  entry: {
    app: path.resolve(APP_PATH,'index.js'),
    vendors: ["jquery","moment"]
  },
  //输出的文件名 合并以后的js会命名为bundle.js
  output: {
    path: BUILD_PATH,
    filename: '[name].[hash].js'
  },
  
  module: {
    loaders: [
      // {
      //   test: /\.scss$/,
      //   loaders: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css!scss' }),
      //   include: APP_PATH
      // },
      {
          test: /\.(scss|css)$/,
          loader: ExtractTextPlugin.extract("style-loader", "css-loader!sass-loader")
      },
      {
        test: /\.(png|jpg)$/,
        loader: 'url-loader?limit=400'
      }
    ]
  },
  //添加我们的插件 会自动生成一个html文件
  plugins: [
    // css打包
    new ExtractTextPlugin("[name].css",{
            allChunks: true
        }),
    //这个使用uglifyJs压缩你的js代码
    new webpack.optimize.UglifyJsPlugin({minimize: true}),
    //把入口文件里面的数组打包成verdors.js
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendors',
      filename: 'vendors.bundle.js',
      minChunks: Infinity
    }),
    new HtmlwebpackPlugin({
      title: '哈哈Hello World app'
    })
    
  ],
};